//
//  ZPBrandDetailVC.m
//  ZhenPin
//
//  Created by zp_liufei on 14-6-9.
//  Copyright (c) 2014年 zhenpin. All rights reserved.
//

#import "ZPBrandDetailVC.h"
#import "ZPBrandShowBigImageVC.h"
#import "UIImageView+WebCache.h"
#import "ZPDetailInfoAndEvaluationVC.h"
#import "ZPSizeShowLableVC.h"
#import "AppDelegate.h"
//#import "UMSocialScreenShoter.h"
#import "logOnViewController.h"
//#import "ZPUMShareShowView.h"
#import "ZPOnlineServeVC.h"
#import "creatOrderViewController.h"
#import "ZPUserModel.h"
//#import "UMSocialWechatHandler.h"
#import "SDWebImagePrefetcher.h"
#import "ZPPictureDetailVC.h"
#import "CartViewController.h"
@interface ZPBrandDetailVC ()
{
    BOOL sizeViewHasInit;
    UIButton *sizeButtonSelect;
    UIButton *colorButtonSelect;
    NSMutableArray *selectSizeArray;
    NSMutableArray *selectColorArray;
    NSMutableArray *productShowImageArray;
    CGRect topRect;
    CGRect bottomRect;
    CGRect currentRect;
    BOOL hasSizeDetail;
    BOOL hasDrawDetail;
    int tagOfNumber;
    BOOL isLogin;
    BOOL webViewRequest;
}
@end
#define SELECT_ITEM_BUTTON_HEIGHT 30
#define SELECT_ITEM_BUTTON_WIDTH 53
#define SELECT_ITEM_LINE_SPACE 10
#define SELECT_ITEM_ITEM_SPACE 8
#define SELECT_SIZEITEM_TAG 800
#define SELECT_COLORITEM_TAG 900
#define BEGIN_X 12
#define ANIMATION_DURATION 0.5f
@implementation ZPBrandDetailVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)awakeFromNib {
    
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //checkLogin
    [[NSNotificationCenter defaultCenter] postNotificationName:StringForCheckLogin object:nil];
//    self.tabBarController.tabBar.hidden = YES;
//    [self checkLogIn];
    [self setLineViewFrame];
    [self getNumberOfProductInShopBag];
}



-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
//    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"商品详情";
    
    //创建成员变量
    [self createMemberVariable];
    //取详情
    [self getProductDetailInfoData];
    
    //取购物袋商品数量
    [self getNumberOfProductInShopBag];

    //取尺码详情
    [self requestProductSizeTable];
    
    
}

-(void)setDetailWebviewValus {
    
}

-(void)getNumberOfProductInShopBag {
    NSDictionary *paraDict;
    
    NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/UserInfo.plist"];
    NSMutableDictionary *dataDic = [[NSDictionary dictionaryWithContentsOfFile:homePath] mutableCopy];
    NSString *memeberId = [dataDic valueForKey:@"memberId"];
    NSString *atoken = [dataDic valueForKey:@"token"];
    
    if ([memeberId length] == 0 ||[memeberId isEqual:[NSNull null]] ||[atoken isEqual:[NSNull null]] ||[atoken length] == 0) {
        
        //
    } else {
        paraDict = @{
                     @"memberid":memeberId
                     };
        AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
        
        [httpManager GET:APIURL"sale/getCartProductNum.json" parameters:paraDict success:^(AFHTTPRequestOperation *operation ,id resultObject){
            numOfProduct = [resultObject[@"cartNum"] intValue];
            if (numOfProduct == 0) {
                numOfPackView.badgeText = @"0";
                numOfPackView.hidden = YES;
            } else {
                numOfPackView.badgeText = [NSString stringWithFormat:@"%d",numOfProduct];
                numOfPackView.hidden = NO;
            }
        } failure:^(AFHTTPRequestOperation *operation,NSError *error) {
            numOfPackView.badgeText = @"0";
            numOfPackView.hidden = YES;
        }];

    }
}



-(void)setNavBackButtonItem {
    UIButton *homeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    homeBtn.frame = CGRectMake(0, 0, 44, 44);
    homeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 20, 0, -10);
    [homeBtn setImage:[UIImage imageNamed:@"home_page"] forState:UIControlStateNormal];
    [homeBtn addTarget:self action:@selector(rightButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:homeBtn];
    self.navigationItem.rightBarButtonItem = rightBarItem;
    [self.navigationController.navigationBar setBackIndicatorImage:
     [UIImage imageNamed:@"return"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:
     [UIImage imageNamed:@"return"]];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}

-(void)leftBarbuttonItemClicked:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark -- request get data for view
-(void)getProductDetailInfoData {
    
    NSDictionary *parameterDict ;
    if (_listId) {
        parameterDict = @{@"product_id": _productId,
                          @"list_id":_listId
                          };
    } else {
        parameterDict = @{@"product_id": _productId
                          };
    }
    AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
    [httpManager GET:APIURL"sale/productInfo.json" parameters:parameterDict success:^(AFHTTPRequestOperation *operation ,id resultObject) {
        [detailHud setHidden:YES];
        
        if (resultObject[@"error"]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:resultObject[@"error"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            alert.delegate = self;
            alert.tag = 200;
            [alert show];
            return ;
        }
        
        if (!resultObject[@"ProductBaseInfo"]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"没有该商品详情,您可以查看其他商品" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            alert.delegate = self;
            alert.tag = 201;
            [alert show];
            return ;
        }
        
        if ([resultObject objectForKey:@"ProductBaseInfo"]) {
            
            productDetailDict = [[resultObject objectForKey:@"ProductBaseInfo"] firstObject];
            
            hasDrawDetail = NO;
            if (productDetailDict[@"productDetail"]) {
                if ([productDetailDict[@"productDetail"] boolValue]) {
                    hasDrawDetail = YES;
                    [_detailTableView reloadData];
                }
                
            }
        }
        if (resultObject[@"SpecialInfo"]) {
            NSDictionary *timeDict = resultObject[@"SpecialInfo"];
            NSString *str = [NSString stringWithFormat:@"%@",timeDict[@"end_time"]];
            [_countDownTimeView setTimeWithTimeIntervalString:str andType:CountDownView_CountDown];
        }
        if ([resultObject objectForKey:@"ProductsActivity"]) {
            productActivityDict = resultObject[@"ProductsActivity"];
        }
        if (resultObject[@"ProductsAttr"]) {
            attriDataArray = resultObject[@"ProductsAttr"];
        }
        if ([resultObject objectForKey:@"ProductsImages"]) {
            [productShowImageArray removeAllObjects];
            [productShowImageArray addObjectsFromArray:[resultObject objectForKey:@"ProductsImages"]];
            _brandShowPageControl.numberOfPages = productShowImageArray.count;
            [_brandImageScrollView setImageWithArray:productShowImageArray withImageSize:CGSizeMake(170, 255)];
            //show image ......
        }
        if ([resultObject objectForKey:@"ProductsColor"]) {
            [selectColorArray removeAllObjects];
            for (NSDictionary *dict in [resultObject objectForKey:@"ProductsColor"]) {
                NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                          [dict objectForKey:@"productId"],@"productId",
                                          [dict objectForKey:@"colorText"],@"colorText",
                                          [dict objectForKey:@"colorname"],@"colorname",
                                          [dict objectForKey:@"urlid"],@"urlid", nil];
                [selectColorArray addObject:userDict];
            }
        }
        if ([resultObject objectForKey:@"ProductSize"]) {
            [selectSizeArray removeAllObjects];
            for (NSDictionary *dict in [resultObject objectForKey:@"ProductSize"]) {
//                NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:
//                                          [dict objectForKey:@"productSpecId"],@"productSpecId",
//                                          [dict objectForKey:@"productId"],@"productId",
//                                          [dict objectForKey:@"specvalue"],@"specvalue",
//                                          [dict objectForKey:@"specValueId"],@"specValueId",nil];
                [selectSizeArray addObject:dict];
            }
        }
        
        if (resultObject[@"ProductsEvaluate"]) {
            NSDictionary *dict = resultObject[@"ProductsEvaluate"];
            productContentNum = [(NSString *)dict[@"evaluateCount"] intValue];
        }
        
        [self setSubViewsValue];
        sizeViewHasInit = NO;
        
    }failure:^(AFHTTPRequestOperation *operation,NSError *error) {
        [detailHud setMode:MBProgressHUDModeText];
        [detailHud setLabelText:@"加载失败，请重试"];
        [detailHud hide:YES afterDelay:1];
    }];
}

-(void)requestProductSizeTable {
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSDictionary *paraDict = @{@"productid": self.productId,
                               };
    [manager GET:APIURL"products/getProductSizeTable.json" parameters:paraDict success:^(AFHTTPRequestOperation *ooperation,id resultObject) {
        NSString *str = resultObject[@"ProductSizeTable"];
        if ([str isEqual:[NSNull null]] || str == nil || str.length == 0) {
            hasSizeDetail = NO;
        } else {
            hasSizeDetail = YES;
        }
        
        [_detailTableView reloadData];
    }failure:^(AFHTTPRequestOperation *operation,NSError *error) {
        hasSizeDetail = NO;
        [_detailTableView reloadData];
    }];
}

-(void)viewDidLayoutSubviews {
    if (currentRect.size.height > 0) {
        _bottomView.frame = CGRectMake(0,   currentRect.size.height+currentRect.origin.y, _bottomView.frame.size.width, 49);
    } else
        _bottomView.frame = CGRectMake(0, self.view.frame.size.height, _bottomView.frame.size.width, -49);
    [self.view bringSubviewToFront:_bottomView];
    [self.view layoutIfNeeded];
    
    [self setLineViewFrame];
//    if ([productDetailDict count] > 0) {
//        [self setBrandNameLabelWidth];
//    }
}

-(void)setLineViewFrame {
    _lineView1.frame = CGRectMake(_lineView1.frame.origin.x, _lineView1.frame.origin.y, _lineView1.frame.size.width, 0.5);
    _lineView2.frame = CGRectMake(_lineView2.frame.origin.x, _lineView2.frame.origin.y, _lineView2.frame.size.width, 0.5);
    _lineView3.frame = CGRectMake(_lineView3.frame.origin.x, _lineView3.frame.origin.y, _lineView3.frame.size.width, 0.5);
    _lineView4.frame = CGRectMake(_lineView4.frame.origin.x, _lineView4.frame.origin.y, _lineView4.frame.size.width, 0.5);
}


-(void)viewDidAppear:(BOOL)animated {
    [self.view bringSubviewToFront:_bottomView];
    [self setLineViewFrame];
}
#pragma mark -- 刷新界面信息数据


-(void)setSubViewsValue {
    [self setBrandNameLabelWidth];
    
    if ([productActivityDict count]>0) {
//        ZPFilterTransverter *tr = [ZPFilterTransverter shareTransverter];
//        NSString *headS = [tr transToActivityTitleFromTypeId:[productActivityDict[@"activityTypeId"]intValue]];
        NSString * string;
        if ([productActivityDict[@"activityTypeId"]intValue] == 2) { //满减
            string = [NSString stringWithFormat:@"            %@",productActivityDict[@"activityName"]];
        } else {
            string = [NSString stringWithFormat:@"%@",productActivityDict[@"activityName"]];
        }
//        NSMutableAttributedString *infoString = [[NSMutableAttributedString alloc] initWithString:string];
//        [infoString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, headS.length)];
//        [infoString addAttribute:NSBackgroundColorAttributeName value:ColorFromRGB(0xff4400) range:NSMakeRange(0, headS.length)];
//        [infoString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Medium" size:14] range:NSMakeRange(0, headS.length)];
        _brandDiscountInfoLabel.text = string;
    } else {
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@""];
        _brandDiscountInfoLabel.attributedText = string;
    }
    _brandColorLabel.textColor = RGB(51, 51, 51);
    _brandSizeLabel.textColor = RGB(51, 51, 51);
    _brandColorLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:15];
    _brandSizeLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:15];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [paragraphStyle setLineSpacing: 3];
    
    NSDictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyle};
    
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:[productDetailDict objectForKey:@"productName"] attributes:attributes];
    
    _brandInfoLabel.attributedText = attributedString;
    
   
    NSString *string;
    if (selectColorArray.count > 0) {
        for (NSDictionary *dict in selectColorArray) {
            if ([[dict objectForKey:@"productId"] intValue] == [_productId intValue]) {
               string = [dict objectForKey:@"colorname"];
            }
        }
        
        if ([string isEqual:[NSNull null]] || string == nil || string.length == 0) {
            string = @"颜色：无";
            
        } else
            string = [NSString stringWithFormat:@"颜色：%@",string];
        
    } else {
        string = @"颜色：无";
    }
    
    NSMutableAttributedString *colorString = [[NSMutableAttributedString alloc] initWithString:string];
    [colorString addAttribute:NSForegroundColorAttributeName value:RGB(102, 102, 102) range:NSMakeRange(3, string.length-3)];
    [colorString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Light" size:13] range:NSMakeRange(3, string.length-3)];
    _brandColorLabel.attributedText = colorString;
    
   
    NSString *str;
    
    if (selectSizeArray.count == 1) {
        NSDictionary *dict = [selectSizeArray firstObject];
        NSString *str1 = [dict objectForKey:@"specvalue"];
        if ([str1 isEqual:[NSNull null]] || str1.length <=0 ) {
            str = @"尺码：均码";
        } else {
            str = [NSString stringWithFormat:@"尺码：%@",[dict objectForKey:@"specvalue"]];
        }
        productSpecid = dict[@"productSpecId"];
    } else
        str = @"尺码：请选择";
    
    NSMutableAttributedString *sizeString = [[NSMutableAttributedString alloc] initWithString:str];
    [sizeString addAttribute:NSForegroundColorAttributeName value:RGB(102, 102, 102) range:NSMakeRange(3, str.length-3)];
    [sizeString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Light" size:13] range:NSMakeRange(3, str.length-3)];
    _brandSizeLabel.attributedText = sizeString;
    
    [self setPriceAndCountDownTime];
}

-(void)setPriceAndCountDownTime {
    if (productDetailDict[@"price"]) {
        NSString *zhen = [NSString stringWithFormat:@"%@",[productDetailDict objectForKey:@"price"]];
        NSString *market = [NSString stringWithFormat:@"%@",[productDetailDict objectForKey:@"marketPrice"]];
        
        [self setPriceOfZhenPin:zhen andMarket:market andDiscount:@"1.23折"];
    }
    
}

-(void)setPriceOfZhenPin:(NSString *)zhen andMarket:(NSString *)market andDiscount:(NSString *)discount{
    NSString *zpPriceStr = [NSString stringWithFormat:@"¥%@  ¥%@",zhen,market];
    NSMutableAttributedString *zpPStr = [[NSMutableAttributedString alloc] initWithString:zpPriceStr];
    [zpPStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, zhen.length+1)];
    [zpPStr addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(zhen.length+3, market.length+1)];
//    [zpPStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(zhen.length+market.length+6, discount.length)];
//    [zpPStr addAttribute:NSBackgroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(zhen.length+market.length+6, discount.length)];
    
    [zpPStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:12] range:NSMakeRange(0, 1)];
    [zpPStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:21] range:NSMakeRange(1, zhen.length)];
    [zpPStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:12] range:NSMakeRange(zhen.length+3, 1)];
    [zpPStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:15] range:NSMakeRange(zhen.length+4, market.length)];
//    [zpPStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Medium" size:12] range:NSMakeRange(zhen.length+market.length+6, discount.length)];
    
    [zpPStr addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(zhen.length+3, market.length+1)];
    
    _brandPriceLabel.attributedText = zpPStr;
    [_brandPriceLabel sizeToFit];
    if ([market floatValue] <= 0) {
        _brandDiscountLabel.hidden = YES;
    } else {
        float dis = [zhen floatValue]/[market floatValue];
        NSString *disString = [NSString stringWithFormat:@"%.1f折",dis*10];
        _brandDiscountLabel.hidden = NO;
        _brandDiscountLabel.text = disString;
        [_brandDiscountLabel sizeToFit];
        [UIView animateWithDuration:0.01 animations:^{
            _brandDiscountLabel.frame = CGRectMake(_brandPriceLabel.frame.origin.x+_brandPriceLabel.frame.size.width+10, _brandDiscountLabel.frame.origin.y, _brandDiscountLabel.frame.size.width+2, _brandDiscountLabel.frame.size.height+1);
        } completion:^(BOOL finished) {
            
        }];
    }
    
}

-(void)setBrandNameLabelWidth {
    CGRect frame = _brandNameLabel.frame;
    frame.size.width += 200;
    _brandNameLabel.frame = frame;
    _brandNameLabel.text = [productDetailDict objectForKey:@"brandname"];
    [_brandNameLabel sizeToFit];
    frame = _brandNameLabel.frame;
    frame.size.width += 16;
    _brandNameLabel.frame = frame;
    _brandNameLabel.center = CGPointMake(self.view.frame.size.width/2, _brandNameLabel.frame.origin.y+_brandNameLabel.frame.size.height/2);
}

#pragma mark -- UIWebView delegate
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    webViewRequest = NO;
    [webHud setHidden:YES];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
    [webHud setHidden:YES];
    webViewRequest = YES;
}

#pragma mark -- UITableView dataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    int number = 1;
    if (hasDrawDetail) {
        number += 1;
    }
    if (hasSizeDetail) {
        number += 1;
    }
    return number;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"detailCell"];
    UILabel *cellTextLabel = (UILabel *)[cell.contentView viewWithTag:100];
    UILabel *lineLabel = (UILabel *)[cell.contentView viewWithTag:200];
    if (!lineLabel) {
        lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 0.5)];
        lineLabel.backgroundColor = [UIColor lightGrayColor];
        lineLabel.tag  = 200;
        [cell.contentView addSubview:lineLabel];
    }
    
    
    if (indexPath.row == 0) {   //详细介绍一定有，尺码对照表，图文详情可无
        if (hasSizeDetail) {
           cellTextLabel.text = @"尺码对照表";
        } else
            cellTextLabel.text = [NSString stringWithFormat:@"详细介绍 & 评价 (%d)",productContentNum];
        
    } else if (indexPath.row == 1) {
        if (hasSizeDetail) {    //如果有尺码对照表
            cellTextLabel.text = [NSString stringWithFormat:@"详细介绍 & 评价 (%d)",productContentNum];
        } else if (hasDrawDetail) { //无尺码对照 有图文
            cellTextLabel.text = @"图文详情 (请在WIFI下打开)";
        }
        
    } else {
        cellTextLabel.text = @"图文详情 (请在WIFI下打开)";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark -- UITableView delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ZPDetailInfoAndEvaluationVC *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ZPDetailInfoAndEvaluationVC"];
    
    if (indexPath.row == 0) {
        if (hasSizeDetail) {
            [dvc setComfromType:1];
        } else
            [dvc setComfromType:2];
    } else if (indexPath.row == 1) {
        if (hasSizeDetail) {
            [dvc setComfromType:2];
        } else if (hasDrawDetail) {
            ZPPictureDetailVC *pvc = (ZPPictureDetailVC *)[self.storyboard instantiateViewControllerWithIdentifier:@"ZPPictureDetailVC"];
            [pvc setProductId:_productId];
            [self.navigationController pushViewController:pvc animated:YES];
            return ;
        }
        
    } else if (indexPath.row == 2) {
        ZPPictureDetailVC *pvc = (ZPPictureDetailVC *)[self.storyboard instantiateViewControllerWithIdentifier:@"ZPPictureDetailVC"];
        [pvc setProductId:_productId];
        [self.navigationController pushViewController:pvc animated:YES];
        return ;
    }
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
    
    for (NSDictionary *dict in attriDataArray) {
        if ([dict[@"isshow"]boolValue]) {
            [array addObject:dict];
        }
    }
    [dvc setTotalEvaluateCount:productContentNum];
    [dvc setAttriArray:array];
    [dvc setProductId:_productId];
    [self.navigationController pushViewController:dvc animated:YES];
}

#pragma mark -- cycle view delegate
-(void)cycleScrollView:(CycleScrollView_Zooming *)scrollView didSelectAtIndex:(NSInteger)index {
    ZPBrandShowBigImageVC *bvc = [[ZPBrandShowBigImageVC alloc] init];
    [bvc setImageDataArray:productShowImageArray];
    [bvc setSelectIndex:index];
    [self.navigationController pushViewController:bvc animated:YES];
}
-(void)cycleScrollView:(CycleScrollView_Zooming *)scrollView scrollToIndex:(NSInteger)index {
    _brandShowPageControl.currentPage = index;
}
#pragma mark -- UIScrollView delegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//- (void)checkLogIn{
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"UserInfo" ofType:@"plist"];
//    NSFileManager *fileManager = [NSFileManager defaultManager];
//    NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/UserInfo.plist"];
//    if (![fileManager fileExistsAtPath:homePath]) {
//        [fileManager createFileAtPath:homePath contents:nil attributes:nil];
//        [fileManager copyItemAtPath:path toPath:homePath error:nil];
//    }
//    
//    
//    NSMutableDictionary *dataDic = [[NSDictionary dictionaryWithContentsOfFile:homePath] mutableCopy];
//    NSString *memberid = [dataDic valueForKey:@"memberId"];
//    NSString *token = [dataDic valueForKey:@"token"];
//    NSString *userName = dataDic[@"userName"];
//    NSString *password = dataDic[@"passwd"];
//    if ([CheckLoginObject isLogin]) {
//        isLogin = NO; //默认标记
//    }else{
//        
//        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//        NSDictionary *params = @{@"memberid": memberid,
//                                 @"access_token": token,
//                                 };
//        
//        [manager POST:APIURL@"ucmembers/checkUser.json" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//            NSString *errorS = responseObject[@"error_code"];
//            NSString *resultString = [NSString stringWithFormat:@"%@",responseObject[@"isOk"]];
//            NSLog(@"error %d",[errorS isEqual:[NSNull null]] || errorS.length==0);
//            if (([errorS isEqual:[NSNull null]] || errorS.length == 0) && ([resultString isEqualToString:@"true"]||[resultString intValue]==1)) {
//                [dataDic writeToFile:homePath atomically:YES];
//                isLogin = YES;//登陆过程标记
//            } else {
//                isLogin = NO;
//                if ([errorS isEqualToString:@"10024"]) {
//                    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//                    NSDictionary *params = @{@"username": userName,
//                                             @"password": password,
//                                             };
//                    
//                    [manager POST:APIURL@"oauth/getAccessToken.json" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//                        NSString *tokeS = responseObject[@"access_token"];
//                        if ([tokeS isEqual:[NSNull null]] || tokeS.length == 0) {
//                            isLogin = NO;
//                        } else {
//                            isLogin = YES;
//                            [dataDic setValue:tokeS forKey:@"token"];
//                            [dataDic writeToFile:homePath atomically:YES];
//                        }
//                        
//                    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//                        isLogin = NO;//接口握手失败标记
//                    }];
//                }
//            }
//            
//        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//            isLogin = NO;//接口握手失败标记
//        }];
//    }
//}

#pragma mark -- -- self clicked methods
- (void)login{
    logOnViewController *loginVC = (logOnViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"logOnViewController"];
    UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    
    navigationVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    navigationVC.navigationBar.tintColor = [UIColor blackColor];
    // present
    [self presentViewController:navigationVC animated:YES completion:nil];
}
//客户咨询
- (IBAction)customReferClicked:(UIButton *)sender {
    ZPOnlineServeVC *olineVC = [[ZPOnlineServeVC alloc] init];
    UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:olineVC];
    nvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    nvc.navigationBar.translucent = NO;
    nvc.navigationBar.tintColor = [UIColor blackColor];
    [self presentViewController:nvc animated:YES completion:nil];
    
}
//活动页
- (IBAction)clickedToActivityView:(UIButton *)sender {
//    if ([productActivityDict count]>0) {
//        UIStoryboard *borad = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        ZPDiscountContaierVC *bvc = [borad instantiateViewControllerWithIdentifier:@"ZPDiscountContaierVC"];
//        [bvc setViewTitle:@"活动详情"];
//        
//        
//        
//        [self.navigationController pushViewController:bvc animated:YES];
//    }
    
}

-(void)createAddToCollectionHud:(NSString *)hudString {
    if (!addtoCollectionHud) {
        addtoCollectionHud = [[MBProgressHUD alloc] initWithView:self.view];
        [addtoCollectionHud setMode:MBProgressHUDModeText];
        [addtoCollectionHud show:YES];
        [self.view addSubview:addtoCollectionHud];
    } else {
        addtoCollectionHud.hidden = NO;
        [addtoCollectionHud show:YES];
    }
    
    [self.view bringSubviewToFront:addtoCollectionHud];
    [addtoCollectionHud setLabelText:hudString];
    [addtoCollectionHud hide:YES afterDelay:1];
    
}

//分享
- (IBAction)shareBrandClicked:(UIButton *)sender {
/*
//    50541187.html
    NSString *strUrl = [NSString stringWithFormat:@"http://m.zhenpin.com/product-%@.html",productDetailDict[@"productId"]];
    [UMSocialWechatHandler setWXAppId:WeChat_ZHENPINMALL_AppKey url:strUrl];
    NSString *shareText = [NSString stringWithFormat:@"%@ %@",[productDetailDict objectForKey:@"productName"],strUrl];
    
    ZPUMShareShowView *shareView = [ZPUMShareShowView shareView];
    shareView.shareText = shareText;
    shareView.shareTitle = [NSString stringWithFormat:@"%@",productDetailDict[@"brandname"]];
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    SDImageCache *imageCache = [manager imageCache];
    NSString *str;
    if (productShowImageArray.count > 0) {
        NSURL *url = Return_imageUrl([productShowImageArray firstObject], 180) ;
        str = [NSString stringWithFormat:@"%@",url];
    }
    UIImage *image = [imageCache imageFromDiskCacheForKey:str];
    if (!image) {
        NSURL *url1 = Return_imageUrl([productShowImageArray firstObject], 510) ;
        NSString *str1 = [NSString stringWithFormat:@"%@",url1];
        image = [imageCache imageFromDiskCacheForKey:str1];
    }
//    image = image ? image:[UIImage imageNamed:@"noimage"];
    if (image) {
        shareView.shareImage = image;
    }
    
    shareView.superViewController = self;
    [shareView showToFrame];
 */
}

//加入购物袋
- (IBAction)addToShopPacket:(UIButton *)sender {
    if ([CheckLoginObject isLogin]) {
        if (!productSpecid) {
            [self showAlertWithTitle:@"提示" message:@"您还没有选择尺码"];
            return ;
        }
        
        NSDictionary *parameterDict;
        NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/UserInfo.plist"];
        NSMutableDictionary *dataDic = [[NSDictionary dictionaryWithContentsOfFile:homePath] mutableCopy];
        NSString *memeberId = [dataDic valueForKey:@"memberId"];
        NSString *atoken = [dataDic valueForKey:@"token"];
        if (tagOfNumber >= 3) {
            [self showAlertWithTitle:@"提示" message:@"单个货品购物车内只能放3件"];
            return;
        }
        if ([memeberId length] == 0 ||[memeberId isEqual:[NSNull null]] ||[atoken isEqual:[NSNull null]] ||[atoken length] == 0) {
            //
        } else {
            parameterDict = @{
                              @"productspecid":productSpecid,
                              @"quantity":[NSString stringWithFormat:@"%d",productQuantity],
                              @"memberid":memeberId,
                              };
            AFHTTPRequestOperationManager *httpManager = [AFHTTPRequestOperationManager manager];
            
            
            [httpManager POST:APIURL"sale/addProduct.json" parameters:parameterDict success:^(AFHTTPRequestOperation *operation ,id resultObject) {
                
                if (resultObject[@"error"]) {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",resultObject[@"error"]] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                } else {
                    NSArray *array = [NSArray arrayWithArray:resultObject[@"productsInCart"]];
                    NSDictionary *dict = [array firstObject];
                    NSArray *itemArray = dict[@"items"];
                    for (NSDictionary *dict_item in itemArray) {
                        if ([dict_item[@"productspecid"] intValue] == [productSpecid intValue]) {
                            if ([dict_item[@"num"] intValue] >= 3) {
                                [self showAlertWithTitle:@"提示" message:@"单个货品购物车内最多只能放3件"];
                            } else {
                                tagOfNumber = [dict_item[@"num"] intValue];
                                [self addProductSuccessWithNumber:productQuantity];
                            }
                            break;
                        }
                    }
                }
                
                
            }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            }];
            
        }

    } else {
        [self login];
    }
    
}
-(void)addProductSuccessWithNumber:(int) num {
    [self getNumberOfProductInShopBag];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeNumberOfProductInCart" object:nil];
    return ;
    if (!addNumberLabel) {
        addNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(180, 10, 40, 20)];
        addNumberLabel.text = [NSString stringWithFormat:@"+%d",productQuantity];
        addNumberLabel.backgroundColor = [UIColor clearColor];
        addNumberLabel.textColor = ColorFromRGB(0xff0100);
        addNumberLabel.hidden = YES;
        [_bottomView addSubview:addNumberLabel];
    } else {
        [addNumberLabel.layer removeAllAnimations];
//        addNumberLabel.frame = CGRectMake(180, 10, 100, 20);
    }
    [self addNumberOfAnimation];
    
}
-(void)addNumberOfAnimation {
    addNumberLabel.hidden = NO;
    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.fillMode = kCAFillModeForwards;
    pathAnimation.removedOnCompletion = NO;
    pathAnimation.duration = .6f;
    pathAnimation.repeatCount = 1;
    pathAnimation.delegate = self;
    CGMutablePathRef curvedPath = CGPathCreateMutable();
    CGPathMoveToPoint(curvedPath, NULL, 180, 10);
    CGPathAddQuadCurveToPoint(curvedPath, NULL, 230, -20, 295, 10);
    pathAnimation.path = curvedPath;
    CGPathRelease(curvedPath);
    [addNumberLabel.layer addAnimation:pathAnimation forKey:@"moveTheSquare"];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    if (flag && [anim isKindOfClass:[CAKeyframeAnimation class]]) {
        addNumberLabel.hidden = YES;
//        numOfProduct += productQuantity;
        [self getNumberOfProductInShopBag];
        
//        numOfPackView.badgeText = [NSString stringWithFormat:@"%d",numOfProduct];
//        if (numOfProduct > 0) {
//            numOfPackView.hidden = NO;
//        }
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeNumberOfProductInCart" object:nil];
}
-(void)showWhenRequestSuccess {
    
}
//购物袋
- (IBAction)clickedToShopPack:(UIButton *)sender {
    if ([CheckLoginObject isLogin]) {
        numOfProduct = 0;
        numOfPackView.hidden = YES;
        CartViewController *cartVC = (CartViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"CartViewController"];
        [self.navigationController pushViewController:cartVC animated:YES];
    } else {
        [self login];
    }
    
}

//展开 or 收起 尺码选择栏
- (IBAction)sizeAndColorSelect:(UIButton *)sender {
    sender.selected = !sender.selected;
    UIImageView *imageV = (UIImageView *)[_brandSelectItemSuperView viewWithTag:300];
    if (sender.selected==YES) { //显示
        imageV.transform = CGAffineTransformMakeRotation(M_PI/2);
        [self setTableViewHeader];
    } else {    //隐藏
        imageV.transform = CGAffineTransformMakeRotation(0);
        _brandSelectItemView.hidden = YES;
        _tableHeaderView.frame = CGRectMake(0, 0, 320, 464);
        
    }
    _detailTableView.tableHeaderView = _tableHeaderView;
    [_detailTableView layoutIfNeeded];
    [_detailTableView setNeedsDisplay];
}

-(void)setTableViewHeader {
    int height;
    if (sizeViewHasInit) {
        _brandSelectItemView.hidden = YES;
        _tableHeaderView.frame = CGRectMake(0, 0, 320, 464+_brandSelectItemView.frame.size.height);
    } else {
        int lineBtnNum = (_brandSelectItemView.frame.size.width-12)/(SELECT_ITEM_BUTTON_WIDTH+SELECT_ITEM_ITEM_SPACE);
        int numSize = [selectSizeArray count];
        int numColor = [selectColorArray count];
        if (numSize < 1) {
            height = 6;
        } else {
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(BEGIN_X, 6, 60, 30)];
            titleLabel.text = @"尺码";
            titleLabel.font = [UIFont systemFontOfSize:15];
            titleLabel.backgroundColor = [UIColor clearColor];
            titleLabel.textColor = RGB(51, 51, 51);
            
            [_brandSelectItemView addSubview:titleLabel];
            height = titleLabel.frame.origin.y + titleLabel.frame.size.height+3;
            for (int i = 0; i < numSize; i ++) {
                NSDictionary *dict = [selectSizeArray objectAtIndex:i];
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(BEGIN_X+(SELECT_ITEM_BUTTON_WIDTH+SELECT_ITEM_ITEM_SPACE)*(i%lineBtnNum), titleLabel.frame.origin.y + titleLabel.frame.size.height+(i/lineBtnNum)*(SELECT_ITEM_BUTTON_HEIGHT+SELECT_ITEM_LINE_SPACE), SELECT_ITEM_BUTTON_WIDTH, SELECT_ITEM_BUTTON_HEIGHT);
                button.tag = SELECT_SIZEITEM_TAG + i;
                [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
                button.titleLabel.font = [UIFont systemFontOfSize:16];
                
                
                [button addTarget:self action:@selector(sizeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
                button.layer.borderColor = RGB(218, 218, 218).CGColor;
                button.layer.borderWidth = 1;
                button.backgroundColor = [UIColor whiteColor];
                NSString *str = [dict objectForKey:@"specvalue"];
                if ([str isEqual:[NSNull null]] || str == nil || str.length == 0) {
                    [button setTitle:@"均码" forState:UIControlStateNormal];
                    
                } else {
                    [button setTitle:[dict objectForKey:@"specvalue"] forState:UIControlStateNormal];

                }
                if (numSize == 1 && i == 0) {
                    sizeButtonSelect = button;
                    sizeButtonSelect.layer.borderColor = RGB(255, 68, 0).CGColor;
                    productSpecid = dict[@"productSpecId"];
                }
                [_brandSelectItemView addSubview:button];
                height = button.frame.origin.y+button.frame.size.height;
            }
            

        }
        if (numColor < 1) {
            
        } else {
            height += 3;
            UILabel  *colorLabel = [[UILabel alloc] initWithFrame:CGRectMake(BEGIN_X, height, 60, 30)];
            colorLabel.textColor = RGB(51, 51, 51);
            colorLabel.backgroundColor = [UIColor clearColor];
            colorLabel.font = [UIFont systemFontOfSize:15];
            colorLabel.text = @"颜色分类";
            [_brandSelectItemView addSubview:colorLabel];
            height = colorLabel.frame.origin.y+colorLabel.frame.size.height;
            for (int i = 0; i < numColor; i ++) {
                NSDictionary *dict = [selectColorArray objectAtIndex:i];
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(BEGIN_X+(SELECT_ITEM_BUTTON_WIDTH+SELECT_ITEM_ITEM_SPACE)*(i%lineBtnNum), colorLabel.frame.origin.y+colorLabel.frame.size.height+(i/lineBtnNum)*(SELECT_ITEM_BUTTON_HEIGHT+SELECT_ITEM_LINE_SPACE), SELECT_ITEM_BUTTON_WIDTH, SELECT_ITEM_BUTTON_HEIGHT);
                button.tag = SELECT_COLORITEM_TAG + i;
                [button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
                button.titleLabel.font = [UIFont systemFontOfSize:16];
                [button setTitle:[dict objectForKey:@"colorname"] forState:UIControlStateNormal];
                button.layer.borderColor = RGB(218, 218, 218).CGColor;
                button.layer.borderWidth = 1;
                [button addTarget:self action:@selector(colorButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
                if ([[dict objectForKey:@"productId"] intValue] == [_productId intValue]) {
                    colorButtonSelect = button;
                    colorButtonSelect.layer.borderColor = RGB(255, 68, 0).CGColor;
                }
//                else if (i == 0) {
//                    colorButtonSelect = button;
//                    colorButtonSelect.layer.borderColor = RGB(255, 68, 0).CGColor;
//                }
                button.backgroundColor = [UIColor whiteColor];
                [_brandSelectItemView addSubview:button];
                height = button.frame.origin.y+button.frame.size.height;
            }
            height += 3;
        }
        
        height += 5;
        if (numColor == 0 && numSize == 0) {
            height = 1;
        }
        _brandSelectItemView.frame = CGRectMake(0, _brandSelectItemView.frame.origin.y, _brandSelectItemView.frame.size.width, height);
        _brandSelectSizeConstraint.constant = height;
        [_brandSelectItemView setNeedsUpdateConstraints];
        sizeViewHasInit = YES;
    }
    _brandSelectItemView.hidden = NO;
    _tableHeaderView.frame = CGRectMake(0, 0, 320, 464+_brandSelectItemView.frame.size.height);

}

-(void)sizeButtonClicked:(UIButton *)btn {
//    int tag = btn.tag - SELECT_SIZEITEM_TAG;
    if (sizeButtonSelect.tag == btn.tag) {
        return ;
    }
    if (sizeButtonSelect) {
        sizeButtonSelect.layer.borderColor = RGB(218, 218, 218).CGColor;
    }
    sizeButtonSelect = btn;
    NSDictionary *dict = [selectSizeArray objectAtIndex:sizeButtonSelect.tag-SELECT_SIZEITEM_TAG];
    sizeButtonSelect.layer.borderColor = RGB(255, 68, 0).CGColor;
    
    productSpecid = [NSString stringWithFormat:@"%@",dict[@"productSpecId"]];
    
//刷新珍品价
    NSString *zhen = [NSString stringWithFormat:@"%@",[dict objectForKey:@"price"]];
    NSString *market = [NSString stringWithFormat:@"%@",[dict objectForKey:@"marketPrice"]];
    if (_isPhoneExclusive) {
        self.phoneExclesivePrice = [NSString stringWithFormat:@"%@",dict[@"premiumPrice"]];
    }
    [self setPriceOfZhenPin:zhen andMarket:market andDiscount:@"8.45折"];
    
    
    NSString *str = [NSString stringWithFormat:@"尺码：%@",[dict objectForKey:@"specvalue"]];
    NSMutableAttributedString *sizeString = [[NSMutableAttributedString alloc] initWithString:str];
    [sizeString addAttribute:NSForegroundColorAttributeName value:RGB(102, 102, 102) range:NSMakeRange(3, str.length-3)];
    [sizeString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Light" size:12] range:NSMakeRange(3, str.length-3)];
    _brandSizeLabel.attributedText = sizeString;
}
-(void)colorButtonClicked:(UIButton *)btn {
    
    if (colorButtonSelect.tag == btn.tag) {
        return ;
    }
    if (colorButtonSelect) {
        colorButtonSelect.layer.borderColor = RGB(218, 218, 218).CGColor;
    }
    colorButtonSelect = btn;
    colorButtonSelect.layer.borderColor = RGB(255, 68, 0).CGColor;
    NSDictionary *dict = [selectColorArray objectAtIndex:colorButtonSelect.tag-SELECT_COLORITEM_TAG];
    if ([[dict objectForKey:@"productId"] intValue] == [_productId intValue]) {
        
        return ;
    }
    
    NSString *str = [NSString stringWithFormat:@"颜色：%@",[dict objectForKey:@"colorname"]];
    NSMutableAttributedString *colorString = [[NSMutableAttributedString alloc] initWithString:str];
    [colorString addAttribute:NSForegroundColorAttributeName value:RGB(102, 102, 102) range:NSMakeRange(3, str.length-3)];
    [colorString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Light" size:12] range:NSMakeRange(3, str.length-3)];
    _brandColorLabel.textColor = RGB(51, 51, 51);
    _brandColorLabel.attributedText = colorString;
    _productId = [dict objectForKey:@"productId"];
    
    [self goToNewDetailViewController];
}
-(void)goToNewDetailViewController {
    
//    [self.navigationController pushViewController:detailVC animated:YES];
}

-(void)changeValueOfTitleLabelWithNumber:(NSInteger)number {
//    _brandCountLabel.text = [NSString stringWithFormat:@"数量：%d",number];
}



-(void)rightButtonClicked {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)showAlertWithTitle:(NSString *)title message:(NSString *)message  {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
    [alert show];
}

- (BOOL)validateEmail:(NSString *)userName{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:userName];
}

- (BOOL)validateMobile:(NSString *)userName
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[0-9])|(17[0-9])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:userName];
}

-(void)createMemberVariable {
    sizeViewHasInit = NO;
    hasSizeDetail = NO;
    webViewRequest = NO;
    _addPacketBtn.clipsToBounds = YES;
    _addPacketBtn.layer.cornerRadius = 5.f;
    productDetailDict = [[NSMutableDictionary alloc] initWithCapacity:0];
    productActivityDict = [[NSMutableDictionary alloc] initWithCapacity:0];
    productShowImageArray = [[NSMutableArray alloc] initWithCapacity:0];
    selectSizeArray = [[NSMutableArray alloc] initWithCapacity:0];
    selectColorArray = [[NSMutableArray alloc] initWithCapacity:0];
    attriDataArray = [[NSMutableArray alloc] initWithCapacity:0];
    [self setNavBackButtonItem];
    productContentNum = 0;
    tagOfNumber = 0;
    
    _brandImageScrollView.delegate = self;
    
    
    numOfProduct = 0;
    productQuantity = 1;
    numOfPackView = [[JSBadgeView alloc] initWithParentView:_toPackBtn alignment:JSBadgeViewAlignmentTopCenter];
    numOfPackView.userInteractionEnabled = NO;
    numOfPackView.badgePositionAdjustment = CGPointMake(4, 5);
    numOfPackView.clipsToBounds = YES;
    numOfPackView.backgroundColor = [UIColor clearColor];
    numOfPackView.hidden = YES;
    
    detailHud = [[MBProgressHUD alloc] initWithView:self.view];
    [detailHud setMode:MBProgressHUDModeIndeterminate];
    [detailHud show:YES];
    [detailHud setHidden:NO];
    if (_isPhoneExclusive) {
        [_addPacketBtn setBackgroundColor:[UIColor grayColor]];
        _addPacketBtn.enabled = NO;
    }
    [self.view addSubview:detailHud];
    //89
    _brandPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 85, 157, 24)];
    _brandPriceLabel.backgroundColor = [UIColor clearColor];
    [_brandInfoView addSubview:_brandPriceLabel];
    _brandDiscountLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 89, 41, 12)];
    _brandDiscountLabel.textAlignment = NSTextAlignmentCenter;
    _brandDiscountLabel.backgroundColor = RGB(255, 1, 0);
    _brandDiscountLabel.layer.cornerRadius = 1.0f;
    _brandDiscountLabel.textColor = [UIColor whiteColor];
    _brandDiscountLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
    _brandDiscountLabel.hidden = YES;
    [_brandInfoView addSubview:_brandDiscountLabel];
    
    _brandNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(128, 9, 65, 21)];
    _brandNameLabel.textAlignment = NSTextAlignmentCenter;
    _brandNameLabel.backgroundColor = [UIColor whiteColor];
    _brandNameLabel.textColor = ColorFromRGB(0x333333);
    _brandNameLabel.font = [UIFont fontWithName:@"Arial" size:17];
    [_brandInfoView addSubview:_brandNameLabel];
    
    _countDownTimeView = [[CountDownView alloc] initWithFrame:CGRectMake(222, 82, 95, 31)];
    _countDownTimeView.labelTextColor = [UIColor redColor];//ColorFromRGB(0xDC2C03)
    _countDownTimeView.stringSyle = CountDownViewString_symbol;
    _countDownTimeView.backgroundColor = [UIColor clearColor];
    _countDownTimeView.showImage = YES;
    _countDownTimeView.imageName = @"detail_clock";
    _countDownTimeView.labelFont = [UIFont systemFontOfSize:14];
    _countDownTimeView.viewAligment = CountDownViewAligment_right;
    [_brandInfoView addSubview:_countDownTimeView];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 200 || alertView.tag == 201) {
        switch (buttonIndex) {
            case 0:
            {
                [self.navigationController popViewControllerAnimated:YES];
            }
                break;
                
            default:
                break;
        }
    }
    
}
@end
